#include "trace_demo.h"
UINT32 g_traceTestTaskId;

void task1()
{
    while(1)
    {
        LOS_TaskDelay(1000);
        printf("-----task 2-----\n");
    }
}

VOID task2(VOID)
{ 
    UINT32 ret;    
    printf("-----------task 1 ---------\n");
#ifndef BEARPI
    // 开启trace
    ret = LOS_TraceStart();   
#else 
    ret = LOS_TrackStart(TRACK_TASK_FLAG);  
#endif
    if (ret != LOS_OK) {        
        printf("trace start error\n");        
        return;    
    }    
    // 触发任务切换的事件  
    LOS_TaskDelay(3);    
#ifndef BEARPI
    // 停止trace    
    LOS_TraceStop();    
    LOS_TraceRecordDump(FALSE);
#else
    LOS_TrackStop(); 
#endif
}

UINT32 trace_entry_sys(VOID){
    UINT32 ret, tid1, tid2;    
#ifndef BEARPI
    // 系统默认情况下已启动trace, 因此可先关闭trace后清除缓存区后，再重启trace                   	  
    LOS_TraceStop();    
    LOS_TraceReset();    
    // 开启任务模块事件记录 
    LOS_TraceEventMaskSet(TRACE_TASK_FLAG);  
#else

#endif
    // 锁住任务调度，防止高优先级任务调度
    LOS_TaskLock();
    TSK_INIT_PARAM_S param = { 0 };
    // 任务参数   
    memset(&traceTestTask, 0, sizeof(TSK_INIT_PARAM_S));    
    param.pfnTaskEntry = (TSK_ENTRY_FUNC)task1;    
    param.pcName       = "task1";    /* 测试任务名称 */    				     
    param.uwStackSize  = 0x2000;    
    param.usTaskPrio   = 10;    
    param.uwResved = 0x0100;
    // 创建任务  
    ret = LOS_TaskCreate(&tid1, &param);    
    if(ret != LOS_OK){        
        printf("create task1 failed %d.\n", ret);        
        return LOS_NOK;    
    }    
  

    param.pfnTaskEntry = (TSK_ENTRY_FUNC)task2;    
    param.pcName       = "task_entry2";    /* 测试任务名称 */    				     
    param.uwStackSize  = 0x2000;    
    param.usTaskPrio   = 11;    
    param.uwResved = 0x0100;
    // 创建任务  
    ret = LOS_TaskCreate(&tid2, &param);    
    if(ret != LOS_OK){        
        printf("TraceTestTask create failed %d.\n", ret);        
        return LOS_NOK;    
    }    
    // 解锁任务调度
    LOS_TaskUnlock();
    return ret;
}
SYS_RUN(trace_entry_sys);